import request from '@/utils/request'

export const categoryApi = {
  // 获取分类列表
  getList(params) {
    return request({
      url: '/v1/categories',
      method: 'get',
      params
    })
  },

  // 获取分类树
  getTree(params) {
    return request({
      url: '/v1/categories/tree',
      method: 'get',
      params
    })
  },

  // 获取分类详情
  getDetail(id) {
    return request({
      url: `/v1/categories/${id}`,
      method: 'get'
    })
  },

  // 创建分类
  create(data) {
    return request({
      url: '/v1/categories',
      method: 'post',
      data
    })
  },

  // 更新分类
  update(id, data) {
    return request({
      url: `/v1/categories/${id}`,
      method: 'put',
      data
    })
  },

  // 删除分类
  delete(id) {
    return request({
      url: `/v1/categories/${id}`,
      method: 'delete'
    })
  },

  // 批量删除
  batchDelete(ids) {
    return request({
      url: '/v1/categories/batch',
      method: 'delete',
      data: { ids }
    })
  },

  // 更新状态
  updateStatus(id, data) {
    return request({
      url: `/v1/categories/${id}/status`,
      method: 'patch',
      data
    })
  },

  // 更新排序
  updateSort(id, data) {
    return request({
      url: `/v1/categories/${id}/sort`,
      method: 'patch',
      data
    })
  },

  // 移动分类
  move(id, data) {
    return request({
      url: `/v1/categories/${id}/move`,
      method: 'patch',
      data
    })
  }
}